﻿#region license
//------------------------------------------------------------------------------
// <copyright company="Ascertaint.org">
//     Copyright (c) Ascertaint.org.  All rights reserved.
// </copyright> 
//
// Authors: Ming Tsai (ming@ascertaint.org)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//------------------------------------------------------------------------------
#endregion

using System;

namespace Ums.CellPhoneInfo {
    /// <summary>
    /// CellPhoneNumber object holds the catch-all mobile number format, which contains 
    /// country code, area code, phone prefix, and phone number.
    /// </summary>
    /// <remarks>
    /// research: 
    /// http://support.microsoft.com/kb/295010
    /// http://forum.nokia.com/document/Cpp_Developers_Library/GUID-96C272CA-2BED-4352-AE7C-E692B193EC06/html/classCommonPhoneParser.html
    /// </remarks>
    [Serializable]
    public class CellPhoneNumber {
        internal bool _isValidNumber = false;        
        string _countryIsoCode;
        string _countryCode;
        string _areaCode;
        string _prefix;
        string _phoneNum;
        internal string _holder;

        /// <summary>
        /// default .ctor
        /// </summary>
        public CellPhoneNumber() {
        }

        /// <summary>
        /// default .ctor
        /// </summary>
        /// <param name="numToParse"></param>
        public CellPhoneNumber(string numToParse) {
            _holder = numToParse;
        }

        /// <summary>
        /// Indicates this phone number is valid.
        /// </summary>
        public bool IsValidNumber {
            get {
                return _isValidNumber;
            }
            set {
                _isValidNumber = value;
            }
        }

        /// <summary>
        /// Returns the shorest possible cell phone number.
        /// </summary>
        /// <returns></returns>
        public string ToshortString() {
            if (string.IsNullOrEmpty(_prefix) && string.IsNullOrEmpty(_phoneNum))
                return _holder;
            else
                return _areaCode + _prefix + _phoneNum;
        }

        /// <summary>
        /// Full length of cell phone number - {country code}{phone prefix}{phone number}.
        /// </summary>
        /// <returns></returns>
        public string ToFullString() {
            if (string.IsNullOrEmpty(_prefix) && string.IsNullOrEmpty(_phoneNum))
                return _holder;
            else
                return _countryCode + _areaCode + _prefix + _phoneNum;
        }

        #region public properties
        /// <summary>
        /// Gets or sets country ISO code
        /// </summary>
        public string CountryIsoCode {
            get {
                return _countryIsoCode;
            }
            set {
                _countryIsoCode = value;
            }
        }

        /// <summary>
        /// Gets or sets country code
        /// </summary>
        /// <remarks>http://www.bcpl.net/~j1m5path/isocodes.html</remarks>
        public string CountryCode {
            get {
                return _countryCode;
            }
            set {
                _countryCode = value;
            }
        }

        /// <summary>
        /// Gets or sets area code
        /// </summary>
        /// <remarks>
        /// http://en.wikipedia.org/wiki/List_of_country_calling_codes
        /// http://en.wikipedia.org/wiki/International_mobile_phone_codes
        /// http://en.wikipedia.org/wiki/List_of_international_call_prefixes
        /// </remarks>
        public string AreaCode {
            get {
                return _areaCode;
            }
            set {
                _areaCode = value;
            }
        }

        /// <summary>
        /// Gets or sets prefix
        /// </summary>
        public string Prefix {
            get {
                return _prefix;
            }
            set {
                _prefix = value;
            }
        }

        /// <summary>
        /// Gets or sets phone number
        /// </summary>
        public string PhoneNumber {
            get {
                return _phoneNum;
            }
            set {
                _phoneNum = value;
            }
        }
        #endregion
    }
}